using RawRestructure.Enums;
using RawRestructure.Models;
using System;
using System.Threading.Tasks;

namespace RawRestructure.Services.Interfaces
{
    /// <summary>
    /// TCP客户端服务接口
    /// </summary>
    public interface ITcpClientService
    {
        /// <summary>
        /// 是否已连接
        /// </summary>
        bool IsConnected { get; }
        
        /// <summary>
        /// 连接状态变化事件
        /// </summary>
        event EventHandler<bool> ConnectionStateChanged;
        
        /// <summary>
        /// 异步连接到服务器
        /// </summary>
        /// <param name="ip">服务器IP</param>
        /// <param name="port">服务器端口</param>
        /// <returns>连接结果</returns>
        Task<bool> ConnectAsync(string ip, int port);
        
        /// <summary>
        /// 异步断开连接
        /// </summary>
        /// <returns>异步任务</returns>
        Task DisconnectAsync();
        
        /// <summary>
        /// 同步断开连接（用于应用关闭时）
        /// </summary>
        void DisconnectSync();
        
        /// <summary>
        /// 异步发送数据包
        /// </summary>
        /// <param name="packet">TCP数据包</param>
        /// <returns>发送结果</returns>
        Task<bool> SendPacketAsync(TcpPacket packet);
        
        /// <summary>
        /// 异步发送数据包
        /// </summary>
        /// <param name="commandType">命令类型</param>
        /// <param name="data">数据</param>
        /// <returns>发送结果</returns>
        Task<bool> SendPacketAsync(CommandType commandType, byte[] data);
    }
} 